package com.xxx.hhh.demo.demo2;



import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
//        接收对象
        DatagramSocket ds = new DatagramSocket(12345);
//        创建新箱子
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes,bytes.length);

            ds.receive(dp);

            byte[] data = dp.getData();
            int length = dp.getLength();

            String s = new String(data,0,length);
            System.out.println(s);
        }


    }
}
